home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / jpsrc2.zip / JBSMOOTH.C < prev    next >
C/C++ Source or Header  |  1991-12-01  |  3KB  |  121 lines

  1. /*
  2.  * jbsmooth.c
  3.  *
  4.  * Copyright (C) 1991, Thomas G. Lane.
  5.  * This file is part of the Independent JPEG Group's software.
  6.  * For conditions of distribution and use, see the accompanying README file.
  7.  *
  8.  * This file contains cross-block smoothing routines.
  9.  * These routines are invoked via the smooth_coefficients method.
  10.  */
  11.  
  12. #include "jinclude.h"
  13.  
  14. #ifdef BLOCK_SMOOTHING_SUPPORTED
  15.  
  16.  
  17. /*
  18.  * Cross-block coefficient smoothing.
  19.  */
  20.  
  21. METHODDEF void
  22. smooth_coefficients (decompress_info_ptr cinfo,
  23.              jpeg_component_info *compptr,
  24.              JBLOCKROW above,
  25.              JBLOCKROW currow,
  26.              JBLOCKROW below,
  27.              JBLOCKROW output)
  28. {
  29.   QUANT_TBL_PTR Qptr = cinfo->quant_tbl_ptrs[compptr->quant_tbl_no];
  30.   long blocks_in_row = compptr->subsampled_width / DCTSIZE;
  31.   long col;
  32.  
  33.   /* First, copy the block row as-is.
  34.    * This takes care of the first & last blocks in the row, the top/bottom
  35.    * special cases, and the higher-order coefficients in each block.
  36.    */
  37.   jcopy_block_row(currow, output, blocks_in_row);
  38.  
  39.   /* Now apply the smoothing calculation, but not to any blocks on the
  40.    * edges of the image.
  41.    */
  42.  
  43.   if (above != NULL && below != NULL) {
  44.     for (col = 1; col < blocks_in_row-1; col++) {
  45.  
  46.       /* See section 13.10 of JPEG-8-R8, or K.8 of JPEG-9-R6.
  47.        *
  48.        * As I understand it, this produces approximations
  49.        * for the low frequency AC components, based on the
  50.        * DC values of the block and its eight neighboring blocks.
  51.        * (Thus it can't be used for blocks on the image edges.)
  52.        */
  53.  
  54.       /* The layout of these variables corresponds to
  55.        * the text in 13.10
  56.        */
  57.       
  58.       JCOEF DC1, DC2, DC3;
  59.       JCOEF DC4, DC5, DC6;
  60.       JCOEF DC7, DC8, DC9;
  61.       
  62.       long       AC01, AC02;
  63.       long AC10, AC11;
  64.       long AC20;
  65.       
  66.       DC1 = above [col-1][0];
  67.       DC2 = above [col  ][0];
  68.       DC3 = above [col+1][0];
  69.       DC4 = currow[col-1][0];
  70.       DC5 = currow[col  ][0];
  71.       DC6 = currow[col+1][0];
  72.       DC7 = below [col-1][0];
  73.       DC8 = below [col  ][0];
  74.       DC9 = below [col+1][0];
  75.       
  76. #define DIVIDE_256(x)    x = ( (x) < 0 ? -((128-(x))/256) : ((x)+128)/256 )
  77.       
  78.       AC01 = (36 * (DC4 - DC6));
  79.       DIVIDE_256(AC01);
  80.       AC10 = (36 * (DC2 - DC8));
  81.       DIVIDE_256(AC10);
  82.       AC20 = (9 * (DC2 + DC8 - 2*DC5));
  83.       DIVIDE_256(AC20);
  84.       AC11 = (5 * ((DC1 - DC3) - (DC7 - DC9)));
  85.       DIVIDE_256(AC11);
  86.       AC02 = (9 * (DC4 + DC6 - 2*DC5));
  87.       DIVIDE_256(AC02);
  88.       
  89.       /* I think that this checks to see if the quantisation
  90.        * on the transmitting side would have produced this
  91.        * answer. If so, then we use our (hopefully better)
  92.        * estimate.
  93.        */
  94.  
  95. #define ABS(x)    ((x) < 0 ? -(x) : (x))
  96.  
  97. #define COND_ASSIGN(_ac,_n,_z)   if ((ABS(output[col][_n] - (_ac))<<1) <= Qptr[_z]) output[col][_n] = (JCOEF) (_ac)
  98.  
  99.       COND_ASSIGN(AC01,  1, 1);
  100.       COND_ASSIGN(AC02,  2, 5);
  101.       COND_ASSIGN(AC10,  8, 2);
  102.       COND_ASSIGN(AC11,  9, 4);
  103.       COND_ASSIGN(AC20, 16, 3);
  104.     }
  105.   }
  106. }
  107.  
  108.  
  109. /*
  110.  * The method selection routine for cross-block smoothing.
  111.  */
  112.  
  113. GLOBAL void
  114. jselbsmooth (decompress_info_ptr cinfo)
  115. {
  116.   /* just one implementation for now */
  117.   cinfo->methods->smooth_coefficients = smooth_coefficients;
  118. }
  119.  
  120. #endif /* BLOCK_SMOOTHING_SUPPORTED */
  121.